import { RequestModel } from '../../models/requestModel.js'
let requsetModel = new RequestModel()
let app=getApp()
Page({
  data: {
    score:0,  //用户积分
    maxMoney:0,  //最大可兑换券金额
    defaultMoney:0,  //默认积分0
    maxNum:0,  //最大次数
    surplus:0   //剩余积分
  },
  onLoad: function (options) {
    let accessToken = app.accessTokenDic.accessToken
    requsetModel.requestScore({
      urlType:`LOGINCOM`,
      url:`score/member/v1/cardinfo?accessToken=${accessToken}`,
    }).then(res=>{
      let maxNum = Math.floor(res / 500)
      let maxMoney = Math.floor(res/500)*10
      this.setData({
        score: res,
        maxMoney: maxMoney,
        maxNum: maxNum,
        surplus:res
      })
    })
  },
  onReady: function () {
 
  },
  onShow: function () {

  },
  onHide: function () {

  },
  onUnload: function () {

  },
  cut(){
    if (this.data.defaultMoney==0){
      return 
    }else{
      let score = this.data.defaultMoney-500
      let surplus = this.data.score - this.data.defaultMoney+500
      this.setData({
        defaultMoney: score,
        surplus: surplus
      })
    }
  },
  add() {
    let tt = this.data.defaultMoney+500
    if(tt>this.data.score){
      return
    }else{
      let score = this.data.defaultMoney + 500
      let surplus = this.data.score - this.data.defaultMoney-500
      this.setData({
        defaultMoney: score,
        surplus: surplus
      })
    }      
  }
})